<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8"/>
		<title>面向对象</title>
	</head>
	<body>
		<script type="text/javascript">
		//创建对象的方式
		//1.通过构造函数来创建对象
		/* var student = new Object();
		student.name = "彭于晏";
		student.age = 22;
		student.sing = function(){
			console.log(this.name+"会唱歌！");
		} */

		//2.通过字面量来创建
		// var student ={
		// 	name:"彭于晏",
		// 	age:22,
		// 	sing(){
		// 		console.log(this.name+"才艺双全！");
		// 	}
		// };
		// console.log(student);


		//对象赋值
/* 		var student = new Object();
		student.name = "子明";
		student.age = 18;

		var teacher = {
			name:"子房",
			age:35,
			s1:student
		};
		student.t1 = teacher;
		console.log(student);
		console.log(teacher);
 */
		

		//循环对象属性
		/* var abc = {
			id: '9CaKrnQhX56',
			type: 2,  // 文章类型
			category: '国际新闻', // 频道
			searchKey: '中美贸易',// 搜索关键字
			keywords: '',
			isPure: 0, // 判断是否是纯文章A页 0显示 1不显示
			aPage: true // a 页声明
		};

		console.log(abc);

		for(var i in abc){
			console.log(i);
			console.log(abc[i]);
			document.write("<h2>"+i+":"+abc[i]+"</h2>");
		}
 */


		//中括号设置属性
		var a = {
			name:"子明",
			age:16,
			sing:function(){
				console.log("爱唱歌");
			}
		};

		console.log(a.name);
		
		a['name'] = '子房';
		console.log(a['name']);
		var shuxing = 'name';
		console.log(a[shuxing]);
		delete a['age'];
		</script>
	</body>
</html>